package com.example.mapper;

import com.example.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("INSERT INTO t_order(order_id, user_id, amount, create_time, status) " +
            "VALUES(#{orderId}, #{userId}, #{amount}, #{createTime}, #{status})")
    void insert(Order order);

    @Select("SELECT * FROM t_order WHERE order_id = #{orderId}")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "createTime", column = "create_time")
    })
    Order findById(@Param("orderId") Long orderId);

    @Select("SELECT * FROM t_order WHERE user_id = #{userId}")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "createTime", column = "create_time")
    })
    List<Order> findByUserId(@Param("userId") String userId);
} 